			MULTIPLE LINEAR REGRESSION

Michael Lloyd (http://www.hsu.edu/faculty/lloydm/ti/prgmtabl.html)
Henderson State University

HISTORY
1.0 November 1997
1.1 April 1998
1.2 May 1998
1.3 August 2015 - updated file to .8xp

DESCRIPTION
Put the data in the columns of [A].

The mean, standard deviation, coefficient of variation, and pairwise
coefficient of determinations are computed for the x and y data. 

The multivariable coefficients, standard deviations of the coefficients,
t-ratios, multiple coefficient of determination, ANOVA summary table, 
p values, predicted y, and confidence intervals for y are also computed.  

**********************************************************************
EXAMPLE

Suppose you have 4 variables: x1, x2, x3, x4 Store the data in the
matrix [A]. For this example, there are 8 rows and 4 columns.

2.9  9.2  13.2  2
2.4  8.7  11.5  3
2.0  7.2  10.8  4
2.3  8.5  12.3  2
3.2  9.6  12.6  3
1.9  6.8  10.6  5
3.4  9.7  14.1  1
2.1  7.9  11.2  3

I rounded the numbers given by the MLREG program for this example to 
3 significant digits.

++++++++++++++++++++++++++++++++

Sample data summary by variable

Means of x1, x2, x3, x4: 2.53, 8.45, 12.0, 2.88 
(Press the left or right arrows to see all the numbers.)

Standard deviations of x1, x2, x3, x4: .570, 1.08,1.23, 1.25

Coefficient of Variation for x1, x2, x3, x4: .226, .127, .102, .434

++++++++++++++++++++++++++++++++

Row i and column j givens the coefficient of determination between 
xi and xj

1.00  .881  .854  .546
.881  1.00  .815  .700
.854  .815  1.00  .812
.546  .700  .812  1.00

++++++++++++++++++++++++++++++++

For example, let x1 be the response variable. (Set the reponse column
to 1.)

The linear model is x1 = -5.92 + .338 x2 + .402 x3 + .263 x4.

The standard deviation of coefficients (standard error):
1.26 .0995 .110 .0851

t ratios (statistics) for the coefficients: -4.72, 3.40, 3.65, 3.09

Standard deviation = .121  R-squared statistic = .974

Regression degrees of freedom = 3
Error degrees of freedom = 4
Total degrees of freedom = 7

Sum of squares of regression = 2.22
Sof of squares of error = .0585
Total sum of squares = 2.28

Mean square of regression = .739
Mean square of error = .0146
F statistics = 50.5

p values for the coefficients: .00920, .0273, .0217, .0366

F p value = .00123

++++++++++++++++++++++++++++++++

Select YES if you want to predict x1. Suppose x2=8.2, x3=11.7, 
and x3=3. Then put {8.2, 11.7, 3} at the x prompt.

Predicted value for x1 = 2.10
Standard deviation of fit = .0472

Suppose the confidence level is 95%. Enter .95 after this prompt.

95% confidence interval for mean x1 = (2.21,2.47)
95% confidence interval for particular x1 = (1.98, 2.70)

********************************************************************** 
VARIABLES USED

[A] = data, y in last column
[B] = predicted y's
[C] = r^2 terms, y data, x values
[D] = multiple of covariance matrix
[E] = SS terms, coefficients
D = mean square of error
E = sum of squares of error
F = F value
I,J = counters
K = degrees of freedom of regression
L=K+1
list Y = y data
list YP = predicted y's
list theta1 = linear regression coefficents
list theta2 = standard deviation of the coefficnents
list theta3 = t ratios for the coefficients
list theta4 = p values for the coefficients
list theta5 = x values
M = degrees of freedom of error
N = data size
Q = mean square of error
R = response variable column, sum of squares of regression
S = multiple standard error of estimate
T = total sum of squares
V = almost variance of predicted Y
Y = predicted y

++++++++++++++++++++++++++++++++++++++++++++++++++++++
PROGRAM LISTING

Disp "DATA IN COLS","OF [A]"
dim([A])\->\\theta\1:\L\\theta\1(1)\->\N:\L\\theta\1(2)\->\L:L-1\->\K
{N,1}\->\dim([B]):Fill(1,[B])
augment([B],[A])\->\[B]
[B]\T\[B]\->\[D]
seq([D](I,1),I,2,L+1)/N\->\\L\\theta\1
Disp "MEAN=":Pause \L\\theta\1
{L,L}\->\dim([C]):Ans\->\dim([E])
For(I,1,L):For(J,1,L)
[D](I+1,J+1)-[D](I+1,1)[D](1,J+1)/N\->\[E](I,J)
End:End
\root\(seq([E](I,I),I,1,L)/(N-1))\->\\L\\theta\2
Disp "STD DEV=":Pause \L\\theta\2
Disp "COEFF VAR=":Pause \L\\theta\2/\L\\theta\1
For(I,1,L):For(J,1,L)
[E](I,J)\^2\/([E](I,I)[E](J,J))\->\[C](I,J)
End:End
Disp "COEF DET=":Pause [C]
{N,1}\->\dim([C])
Input "RESPONSE COL=",R
For(I,1,N):[A](I,R)\->\[C](I,1):End
If R\<=\K:Then
For(J,R+1,L):For(I,1,N)
[B](I,J+1)\->\[B](I,J)
End:End
[B]\T\[B]\->\[D]
End
{L,L}\->\dim([D]):[D]\^-1\\->\[D]
{N,L}\->\dim([B])
[B]\T\[C]:[D]Ans\->\[E]
Matr\>\list([E],\L\\theta\1)
Disp "COEF \L\\theta\1=":Pause \L\\theta\1
[B][E]\->\[B]
Matr\>\list([C],\L\Y)
Matr\>\list([B],\L\YP)
mean(\L\Y)\->\Y
sum((\L\Y-Y)\^2\)\->\T
sum((\L\Y-\L\YP)\^2\)\->\E
DelVar \L\Y:DelVar \L\YP
N-L\->\M:T-E\->\R:R/K\->\Q:E/M\->\D:\root\(D)\->\S:Q/D\->\F
S\root\(seq([D](I,I),I,1,L))\->\\L\\theta\2
Disp "STDEV \L\\theta\2=":Pause \L\\theta\2
\L\\theta\1/\L\\theta\2\->\\L\\theta\3
Disp "T-RATIO \L\\theta\3=":Pause \L\\theta\3
Disp "S=",S
Disp "R\^2\=",R/T
Pause 
Disp "REG DF=",K
Disp "ERROR DF=",M
Disp "TOTAL DF=",N-1
Pause 
Disp "SS REG=",R
Disp "SS ERROR=",E
Disp "SS TOTAL=",T
Pause 
Disp "MS REG=",Q
Disp "MS ERROR=",D
Disp "F=",F
Pause 
Disp "COEF P \L\\theta\4="
1-2seq(tcdf(0,abs(\L\\theta\3(I)),M),I,1,L)\->\\L\\theta\4
Pause \L\\theta\4
Disp "F P VALUE="
Pause 1-\F\cdf(0,F,K,M)
Lbl C
Menu("PREDICT Y?","YES",A,"QUIT",B)
Lbl A
Input "X{}=",\L\\theta\5
{L,1}\->\dim([C])
1\->\[C](1,1)
For(I,1,K):\L\\theta\5(I)\->\[C](I+1,1):End
[E]\T\[C]
Ans(1,1)\->\Y
Disp "PREDICTED Y=",Y
[C]\T\[D][C]
Ans(1,1)\->\V
Disp "STDDEV FIT=",S\root\(V)
Input "CONF. LEVEL=",C
TInterval 0,\root\(M+1),M+1,C
upper\->\T
Disp "C.I.="
Pause Y+{\(-)\1,1}TS\root\(V)
Disp "P.I.="
Pause Y+{\(-)\1,1}TS\root\(1+V)
Goto C
Lbl B
DelVar [C]:DelVar [D]:DelVar [E]:DelVar \L\\theta\5
